package com.java.study.provider.controller;

import com.java.study.provider.vo.PersonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {

    @Autowired
    private Environment env;

    @GetMapping("hello")
    public String hello(String name) {
        if (StringUtils.isEmpty(name)) {
            name = " I'm default service provider";
        }
        return "Hello::" + name + " I‘m server::" + env.getProperty("server.port");
    }

    @GetMapping("person/{personId}")
    public PersonVO findPerson(@PathVariable Integer personId, HttpServletRequest request){
        PersonVO personVO = new PersonVO();
        personVO.setId(personId);
        personVO.setName("King Campus");
        personVO.setAge(30);
        personVO.setMessage(request.getRequestURL().toString());
        return personVO;
    }
}
